package com.listeningframework.boot.cors;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "listening.cors")
public class CorsProperties {
    /**
     * Support Cors
     */
    private boolean enabled             = false;
    /**
     * Allowed Cors Url Pattern For Spring Mvc
     */
    private String  allowedPattern      = "/**";
    /**
     * Cors Allow Origins
     */
    private String  allowedOrigins      = CorsConstants.DEFAULT_ALLOWED_ORIGINS;
    /**
     * Cors Allow Http Methods
     */
    private String  allowedHttpMethods  = CorsConstants.DEFAULT_ALLOWED_HTTP_METHODS;
    /**
     * Cors Allow Http Headers
     */
    private String  allowedHttpHeaders  = CorsConstants.DEFAULT_ALLOWED_HTTP_HEADERS;
    /**
     * Cors Exposed Headers
     */
    private String  exposedHeaders      = CorsConstants.DEFAULT_EXPOSED_HEADERS;
    /**
     * Cors Supports Credentials
     */
    private String  supportsCredentials = CorsConstants.DEFAULT_SUPPORTS_CREDENTIALS;
    /**
     * Cors prefight max age
     */
    private String  preflightMaxAge     = CorsConstants.DEFAULT_PREFLIGHT_MAXAGE;
    /**
     * decorate request
     */
    private String  decorateRequest     = CorsConstants.DEFAULT_DECORATE_REQUEST;

    public boolean isAllowAnyOrigins() {
        return StringUtils.equals(allowedOrigins, "*");
    }

    public String getAllowedOrigins() {
        return allowedOrigins;
    }

    public void setAllowedOrigins(String allowedOrigins) {
        this.allowedOrigins = allowedOrigins;
    }

    public String getAllowedHttpMethods() {
        return allowedHttpMethods;
    }

    public void setAllowedHttpMethods(String allowedHttpMethods) {
        this.allowedHttpMethods = allowedHttpMethods;
    }

    public String getAllowedHttpHeaders() {
        return allowedHttpHeaders;
    }

    public void setAllowedHttpHeaders(String allowedHttpHeaders) {
        this.allowedHttpHeaders = allowedHttpHeaders;
    }

    public String getExposedHeaders() {
        return exposedHeaders;
    }

    public void setExposedHeaders(String exposedHeaders) {
        this.exposedHeaders = exposedHeaders;
    }

    public String getSupportsCredentials() {
        return supportsCredentials;
    }

    public void setSupportsCredentials(String supportsCredentials) {
        this.supportsCredentials = supportsCredentials;
    }

    public String getPreflightMaxAge() {
        return preflightMaxAge;
    }

    public void setPreflightMaxAge(String preflightMaxAge) {
        this.preflightMaxAge = preflightMaxAge;
    }

    public String getDecorateRequest() {
        return decorateRequest;
    }

    public void setDecorateRequest(String decorateRequest) {
        this.decorateRequest = decorateRequest;
    }

    public String getAllowedPattern() {
        return allowedPattern;
    }

    public void setAllowedPattern(String allowedPattern) {
        this.allowedPattern = allowedPattern;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

}
